package me.samlss.lighter_demo.slice;

import me.samlss.lighter_demo.BuildConfig;
import me.samlss.lighter_demo.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
/**
 * @author: zhu_zhonglin
 * @time: 2021/4/25
 */
public class MainAbilitySlice extends AbilitySlice implements Component.ClickedListener {
    Button btn_normal;
    Button btn_recyclerview;
    Button btn_list_view;
    Button btn_grid_view;
    Button btn_scroll_view;
    Button btn_view_pager;
    Button btn_dialog;
    Button btn_fragment;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        initView();
    }

    private void initView() {
        btn_normal = (Button) findComponentById(ResourceTable.Id_btn_normal);
        btn_normal.setClickedListener(this);
        btn_recyclerview = (Button) findComponentById(ResourceTable.Id_btn_recyclerview);
        btn_recyclerview.setClickedListener(this);
        btn_list_view = (Button) findComponentById(ResourceTable.Id_btn_list_view);
        btn_list_view.setClickedListener(this);
        btn_grid_view = (Button) findComponentById(ResourceTable.Id_btn_grid_view);
        btn_grid_view.setClickedListener(this);
        btn_scroll_view = (Button) findComponentById(ResourceTable.Id_btn_scroll_view);
        btn_scroll_view.setClickedListener(this);
        btn_view_pager = (Button) findComponentById(ResourceTable.Id_btn_view_pager);
        btn_view_pager.setClickedListener(this);
        btn_dialog = (Button) findComponentById(ResourceTable.Id_btn_dialog);
        btn_dialog.setClickedListener(this);
        btn_fragment = (Button) findComponentById(ResourceTable.Id_btn_fragment);
        btn_fragment.setClickedListener(this);
    }

    private void click(int resId) {
        switch (resId) {
            case ResourceTable.Id_btn_normal: {
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName(BuildConfig.PACKAGE_NAME)
                        .withAbilityName(BuildConfig.PACKAGE_NAME + ".RelativeLayoutAbility")
                        .build();
                Intent i = new Intent();
                i.setOperation(operation);
                startAbility(i);
                break;
            }
            case ResourceTable.Id_btn_recyclerview: {
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName(BuildConfig.PACKAGE_NAME)
                        .withAbilityName(BuildConfig.PACKAGE_NAME + ".RecyclerViewAbility")
                        .build();
                Intent i = new Intent();
                i.setOperation(operation);
                i.setParam("title", "RecyclerView");
                startAbility(i);
                break;
            }
            case ResourceTable.Id_btn_list_view: {
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName(BuildConfig.PACKAGE_NAME)
                        .withAbilityName(BuildConfig.PACKAGE_NAME + ".RecyclerViewAbility")
                        .build();
                Intent i = new Intent();
                i.setOperation(operation);
                i.setParam("title", "ListView");
                startAbility(i);
                break;
            }
            case ResourceTable.Id_btn_grid_view: {
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName(BuildConfig.PACKAGE_NAME)
                        .withAbilityName(BuildConfig.PACKAGE_NAME + ".GridViewAbility")
                        .build();
                Intent i = new Intent();
                i.setOperation(operation);
                startAbility(i);
                break;
            }
            case ResourceTable.Id_btn_scroll_view: {
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName(BuildConfig.PACKAGE_NAME)
                        .withAbilityName(BuildConfig.PACKAGE_NAME + ".ScrollViewAbility")
                        .build();
                Intent i = new Intent();
                i.setOperation(operation);
                startAbility(i);
                break;
            }
            case ResourceTable.Id_btn_view_pager: {
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName(BuildConfig.PACKAGE_NAME)
                        .withAbilityName(BuildConfig.PACKAGE_NAME + ".ViewPagerAbility")
                        .build();
                Intent i = new Intent();
                i.setOperation(operation);
                startAbility(i);
                break;
            }
            case ResourceTable.Id_btn_dialog: {
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName(BuildConfig.PACKAGE_NAME)
                        .withAbilityName(BuildConfig.PACKAGE_NAME + ".DialogAbility")
                        .build();
                Intent i = new Intent();
                i.setOperation(operation);
                startAbility(i);
                break;
            }
            case ResourceTable.Id_btn_fragment: {
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName(BuildConfig.PACKAGE_NAME)
                        .withAbilityName(BuildConfig.PACKAGE_NAME + ".FragmentAbility")
                        .build();
                Intent i = new Intent();
                i.setOperation(operation);
                startAbility(i);

                break;
            }
        }
    }

    @Override
    public void onClick(Component component) {
        click(component.getId());
    }
}
